package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "商品规格参数管理模块")
@RequestMapping("/admin/product/spec")
public class ProductSpecController {

    @Resource
    ProductSpecService productSpecService;
    @Operation(summary = "查询所有规格参数")
    @GetMapping("findAll")
    public Result findAll(){
        List<ProductSpec> productSpecList =  productSpecService.findAll();
        return Result.ok().data(productSpecList);
    }
    @Operation(summary = "分页查询规格参数")
    @GetMapping("page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize){
        PageInfo<ProductSpec> pageInfo =  productSpecService.page(pageNum,pageSize);
        return Result.ok().data(pageInfo);
    }

    @Operation(summary = "删除规格参数")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        productSpecService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "根据id查询规格参数")
    @DeleteMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        ProductSpec productSpec = productSpecService.getById(id);
        return Result.ok().data(productSpec);
    }
    @Operation(summary = "更新规格参数")
    @PutMapping("updateById")
    public Result updateById(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.ok();
    }

    @Operation(summary = "新增规格参数")
    @PostMapping("save")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.ok();
    }

}
